export const randomString = function(len) {
    const str = 'ABCDEFGHIJKIMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    let num = '';
	for (let i = 0; i < len; i++) {
		num += str.charAt(Math.floor(Math.random() * str.length));
	}
	return num;
}

export const checkModbile = function (mobile) {
	var re = /^1[3,4,5,6,7,8,9][0-9]{9}$/;
	var result = re.test(mobile); 
	if(!result) {
		// alert("手机号码格式不正确！");
		return false;
	}
	return true;
}
// 验证球镜柱镜的值
export const isValidSPH = function (sph) {
	var re = /^[-,+]\d+(\.\d+)?$/
	return re.test(sph); 
}

export const readFileBase64 = async function(file) {
	return new Promise((resolve, reject) => {
		uni.getFileSystemManager().readFile({
			filePath: file,
			encoding: 'base64',
			success: (ret) => {
				resolve(ret);
			},
			fail: (err) => {
				reject(err);
			},
		})
	})
}
export const urlTobase64 = async function(url) {
	return new Promise((resolve, reject) => {
		uni.downloadFile({
			url,
			success: (res) => {
				uni.getFileSystemManager().readFile({
					filePath: res.tempFilePath,
					encoding: 'base64',
					success: (res) => {
						resolve(res.data)
					},
					fail: (err) => {
						reject(err);
					},
				})
			},
			fail: (err) => {
				reject(err)
			},
		})
	});
}